GRAPHS
Photo by JJ Ying on Unsplash
…to ensure that the results of science are rapidly disseminated to the public throughout the world,
in a fashion that conveys their significance for knowledge, culture and daily life…
— Nature’s mission statement
An analysis of Nature magazine’s co-citation network comprised of more than 88,000 papers published since 1900.
df_nodes <- read.csv("archetypes/150-yrs-of-nature/cocite-nodes.csv", header = TRUE, stringsAsFactors = FALSE)
df_nodes <- df_nodes %>% select(NatureID, Title, PubYear)
df_nodes <- df_nodes[!duplicated(df_nodes), ]
df_nodes
df_edges <- read.csv("archetypes/150-yrs-of-nature/cocite-edges.csv", header = TRUE, stringsAsFactors = FALSE)
df_edges
df_nodes_filtered <- filter(df_nodes, PubYear > 2014)
df_nodes_filtered
df_edges_filtered <- filter(df_edges, source %in% df_nodes_filtered$NatureID & target %in% df_nodes_filtered$NatureID)
# df_edges_filtered
df_graph <- graph_from_data_frame( df_edges_filtered, directed = FALSE, vertices = df_nodes_filtered )
# remove isolates
isolates <- which(degree(df_graph)==0)
df_graph <- delete.vertices(df_graph, isolates)
# df_graph
Creating numerical fields for the Nodes set in order to attribute the nodes size and/or color
## Creating centrality numerical field for the Nodes
# centrality_alpha(), centrality_authority(), centrality_betweenness()
# centrality_power(), centrality_closeness(), centrality_eigen()
# centrality_hub(), centrality_pagerank(), centrality_subgraph()
# centrality_degree(), centrality_edge_betweenness(), centrality_manual()
# centrality_closeness_harmonic(), centrality_closeness_residual()
# centrality_closeness_generalised()
# centrality_communicability() , centrality_communicability_odd()
# centrality_communicability_even()
# centrality_subgraph_odd(), centrality_subgraph_even()
# centrality_katz(), centrality_betweenness_network()
# centrality_betweenness_current(), centrality_betweenness_communicability()
# centrality_betweenness_rsp_simple(), centrality_betweenness_rsp_net()
# centrality_information(), centrality_decay()
# centrality_random_walk(), centrality_expected()
cg <- df_graph %>%
as_tbl_graph() %>%
activate(nodes) %>%
# associating random numerical value to nodes to differentiate their colors and sizes
mutate(centrality = centrality_betweenness())
# cg
## Creating group numerical field for the Nodes
# group_components(), group_edge_betweenness()
# group_fast_greedy(), group_infomap()
# group_label_prop(), group_leading_eigen()
# group_louvain(), group_optimal()
# group_spinglass(), group_walktrap()
# group_biconnected_component()
cg <- cg %>%
activate(nodes) %>%
# use functions to compute numerical values to attribute the edge width and/or color
mutate(group = group_louvain())
# cg
# Layouts can be computationally intensive
# Un-comment only for use
# igraph
# layout <- create_layout(cg, layout = 'dh')
# layout <- create_layout(cg, layout = 'fr')
# layout <- create_layout(cg, layout = 'gem')
# layout <- create_layout(cg, layout = 'lgl')
# layout <- create_layout(cg, layout = 'sugiyama')
# layout <- create_layout(cg, layout = 'star')
# layout <- create_layout(cg, layout = 'kk', maxiter = 100)
# layout <- create_layout(cg, layout = 'drl')
# layout <- create_layout(cg, layout = 'linear')
# layout <- create_layout(cg, layout = 'linear' , circular = TRUE)
# ggraph
# layout <- create_layout(cg, layout = 'linear')
# layout <- create_layout(cg, layout = 'linear', circular = TRUE)
layout <- create_layout(cg, layout = 'stress')
# layout <- create_layout(cg, layout = 'sparse_stress')
# layout <- create_layout(cg, layout = 'backbone')
# layout <- create_layout(cg, layout = 'pmds')
# layout <- create_layout(cg, layout = 'eigen')
# layout <- create_layout(cg, layout = 'centrality')
# layout <- create_layout(cg, layout = 'focus')
# layout <- create_layout(cg, layout = 'dendrogram')
# layout <- create_layout(cg, layout = 'unrooted')
# layout <- create_layout(cg, layout = 'matrix')
# layout <- create_layout(cg, layout = 'hive')
# layout <- create_layout(cg, layout = 'fabric')
# graphlayouts
# layout <- create_layout(cg, layout = "nicely")
# layout <- create_layout(cg, layout = "stress")
# layout <- create_layout(cg, layout = "focus", focus = 1)
# Edge Types
# geom_edge_arc, geom_edge_arc0, geom_edge_arc2
# geom_edge_density, geom_edge_diagonal, geom_edge_diagonal0, geom_edge_diagonal2
# geom_edge_elbow, geom_edge_elbow0, geom_edge_elbow2
# geom_edge_fan, geom_edge_fan0, geom_edge_fan2
# geom_edge_hive, geom_edge_hive0, geom_edge_hive2
# geom_edge_link, geom_edge_link0, geom_edge_link2
# geom_edge_loop, geom_edge_loop0
theme_opts <- theme(
text = element_text(family = "inconsolata"),
legend.position='none'
)
v1 <- ggraph(layout) +
geom_edge_link() +
geom_point_interactive(aes(x = x, y = y, color = group, size = centrality, tooltip = Title, data_id = name)) +
scale_color_viridis(option = "plasma") +
scale_size(range = c(1,12)) +
theme_graph() +
theme_opts
girafe(ggobj = v1, width_svg = 16, height_svg = 16,
options = list(opts_sizing(rescale = TRUE, width = 1.0))
)